package com.ttx.pattern.example.composite.after;

import java.util.Iterator;

/**
 * @author TimFruit
 * @date 2019/7/8 14:58
 */

public class Client {

    public static void main(String[] args) {
        
        Component root=new Composite("composite_0_1");
        Component com1=new Composite("composite_1_1");
        com1.add(new Leaf("left_2_1"));
        com1.add(new Leaf("left_2_2"));
        
        root.add(com1);


        root.add(new Leaf("leaf_1_2"));
        root.add(new Leaf("leaf_1_3"));
        
        //先打印根节点
        root.operation();
        
        Iterator<Component> iterator=root.iterator();
        Component next=null;
        while(iterator.hasNext()){
            next=iterator.next();
            next.operation();
        }
        
        
        /*
        composite: composite_0_1
        composite: composite_1_1
        leaf: left_2_1
        leaf: left_2_2
        leaf: leaf_1_2
        leaf: leaf_1_3
         */
        
    }
    
}
